<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/ftl/css/bootstrap.min.css">
    <link rel="stylesheet" href="/ftl/css/laypage.css">

    <script src="/ftl/js/vue/vue.min.js"></script>
    <script src="/ftl/js/jquery/jquery.min.js"></script>
    <script src="/ftl/js/laypage/laypage.js" charset="utf-8"></script>
    <script src="/ftl/js/layer/layer.js" charset="utf-8"></script>
</head>
<body>
<div id="app" class="container">
    <#--${Session["user"].userName}，-->
    欢迎你2222

    <form class="form-inline bg-danger" role="form">
        查询条件：
        <div class="form-group">
            <label class="sr-only" for="username">用户名称</label>
            <input type="text" class="form-control" id="username" placeholder="用户名称">
        </div>
        <div class="form-group">
            <label class="sr-only" for="userage">用户年龄</label>
            <input type="text" class="form-control" id="userage" placeholder="用户年龄">
        </div>
        <button type="button" id="findUser" class="btn btn-success">查询用户</button>
        <button type="button" id="addUserBtn" class="btn btn-danger">增加用户</button>
    </form>

    <div class="table-responsive">
        <table class="table">
            <thead>
            <tr class="success">
                <td>序号</td>
                <td>用户</td>
                <td>年龄</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr class="active" v-for="(item,index) in result">
                <th>{{index+1}}</th>
                <td>{{item.userName}}</td>
                <td>{{item.age}}</td>
                <td><a href="#" @click="editEvent(item.id)">编辑</a>&nbsp;<a href="">删除</a></td>
            </tr>
            </tbody>
            <tr>
                <td colspan="3">
                    <div id="pagenav"></div>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            result: []
        }
    });

    var getUsersPageList = function (curr) {
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/getPage.do',
            data: {
                pageNum: curr || 1,
                pageSize: 3,
                userName: $("#username").val()
            },
            success: function (result) {
                app.result = result.page;
                laypage({
                    cont: 'pagenav',
                    skin: '#008B8B',
                    pages: result.totalPage,
                    first: true,
                    last: true,
                    curr: curr || 1,

                    jump: function (obj, first) {
                        if (!first) {
                            getUsersPageList(obj.curr);
                        }
                    }
                });
            }
        });
    }

    getUsersPageList();

    $("#findUser").click(function () {
        getUsersPageList();
    });


    var editEvent = function (id) {
        layer.open({
            type: 2,
            title: '编辑用户',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['1000px', '600px'],
            content: '/editPage.do?id=' + id,
            end: function () {
                getUsersPageList();
            }
        });
    }


</script>

</body>
</html>